package reflect;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Scanner;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException {
        // 获取 Class 对象的两种方式

        /*Class c1 = Class.forName("java.lang.String");
        Class c2 = Class.forName("java.util.ArrayList");


        Class c5 = String.class;
        Class c6 = int.class;
        Class c7 = void.class;
        Class c8 = Class.class;
        Class c9 = ArrayList.class;
        Scanner sc = new Scanner(System.in);
        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        System.out.println(c5.hashCode());
        System.out.println(c6);
        System.out.println("请输入一个类名");
        String name = sc.next();
        Class c3 = Class.forName(name);



        System.out.println();*/

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个类名");
        String name = scan.nextLine();
        Class cls = Class.forName(name);
        System.out.println("获取类的完全限定名:"+cls.getName());
        System.out.println("获取类的简单名:"+cls.getSimpleName());
        Package package1 = cls.getPackage();
        System.out.println("获取包名:"+package1.getName());

        Method[] methods = cls.getMethods();
        System.out.println("有多少个方法:"+methods.length);
        for (Method m:methods){
            System.out.println(m.getName());
        }

    }
}
